package multiThred;

import java.util.concurrent.locks.Lock;

public class MutliThreadPrint {

    private static Object lock = new Object();
    private static  int statue = 0;

    private static void printer(String name, int target) {
        for (int i = 0; i < 10; i++) {
            synchronized (lock) {
                while (target != statue) {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(name + " ");
                statue = (statue + 1) % 3;
                lock.notifyAll();
            }
        }
    }

    public static void main(String[] args) {
        new Thread(() -> printer("A", 0)).start();
        new Thread(() -> printer("B", 1)).start();
        new Thread(() -> printer("C", 2)).start();
    }
}
